/*
 * Copyright (c) 2021. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package com.xxpure.compare;

import com.xxpure.Point.MyPoint;
import com.xxpure.kmeans.KMeansInterface;

import java.util.ArrayList;

/**
 * @program: KNN
 * @author: Mr.xiao
 * @email: 1347772729@qq.com
 * @create: 2021-07-04 16:46
 **/
public class KMeansCompare implements KMeansInterface<MyPoint> {
    private int cnt = 0;

    @Override
    public MyPoint getAverageSample(ArrayList<MyPoint> points) {
        int x = 0, y = 0;
        for (var point : points) {
            x += point.getX();
            y += point.getY();
        }
        if (points.size() == 0)
            return null;
        return new MyPoint(x / points.size(), y / points.size());
    }

    @Override
    public boolean isOver() {
        return cnt++ > 100;
    }

    @Override
    public int getDistance(MyPoint elements, MyPoint point) {
        return (elements.getX() - point.getY()) * (elements.getX() - point.getX()) + (elements.getY() - point.getY()) * (elements.getY() - point.getY());
    }
}
